﻿@* @inherits AppAuthComponentBase *@
@inherits AppComponentBase
@* @inject ServiceStackStateProvider AuthStateProvider; *@
@inject NavigationManager NavigationManager;
@inject IJSRuntime JS

<header class="border-b border-gray-200 dark:border-gray-800 pr-3">
    <div class="flex flex-wrap items-center">
        <div class="flex flex-grow flex-shrink flex-nowrap justify-end items-center">
            <nav class="relative flex flex-grow">
                <ul class="flex flex-wrap items-center justify-end w-full m-0">
                    @foreach (var item in NavItems)
                    {
                        <li class="relative flex flex-wrap just-fu-start m-0">
                            <NavLink href=@item.Href class="flex items-center justify-start mw-full p-4 hover:text-green-600 dark:hover:text-green-400">@item.Label</NavLink>
                        </li>
                    }

                    <li class="relative flex flex-wrap just-fu-start m-0">
                        <NavLink href=@LoginUrl class="m-2 mr-4">
                            <SecondaryButton>
                                Sign In
                            </SecondaryButton>
                        </NavLink>
                    </li>

                    <li class="relative flex flex-wrap just-fu-start m-0">
                        <DarkModeToggle @rendermode="@RenderMode.Auto" />
                    </li>

                </ul>
            </nav>
        </div>
    </div>
</header>

@code {
    bool ShowAuthMenu = false;

    string LoginUrl { get; set; } = "/signin";
    
    List<NavItem> NavItems { get; set; } = new();

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (NavItems.Count == 0)
            NavItems = await JS.GetNavItemsAsync("TOP");
    }
    
    protected override Task OnParametersSetAsync()
    {
        LoginUrl = NavigationManager.GetLoginUrl();
        return base.OnParametersSetAsync();
    }

    async Task logout()
    {
        // await AuthStateProvider.LogoutAsync();
        NavigationManager.NavigateTo(LoginUrl, true);
    }
}
